package com.example.exam.MeunFrgment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import androidx.fragment.app.Fragment;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.exam.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class PictureFragment extends Fragment {
    @BindView(R.id.picture_imageView)
    CircleImageView pictureImageView;
    @BindView(R.id.picture_button1)
    Button pictureButton1;
    @BindView(R.id.picture_button2)
    Button pictureButton2;
    @BindView(R.id.picture_button3)
    Button pictureButton3;
    @BindView(R.id.picture_button4)
    Button pictureButton4;
    @BindView(R.id.picture_button5)
    Button pictureButton5;
    @BindView(R.id.picture_button6)
    Button pictureButton6;

    public PictureFragment() {
        // Required empty public constructor
    }
    private View view;

    @Override
    public void onDestroy() {
        super.onDestroy();
        view=new View(getContext());
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_picture, container, false);
        ButterKnife.bind(this,view);
        return view;
    }
    @OnClick({R.id.picture_button1, R.id.picture_button2, R.id.picture_button3, R.id.picture_button4, R.id.picture_button5, R.id.picture_button6})
    public void onViewClicked(View view) {
        Toast.makeText(getContext(),"asdf",Toast.LENGTH_SHORT).show();
        switch (view.getId()) {
            case R.id.picture_button1:
                Glide.with(getContext()).load(R.drawable.ww).into(pictureImageView);
                break;
            case R.id.picture_button2:
                RequestOptions fallback = new RequestOptions().fallback(R.drawable.ww);//回调中
                Glide.with(getContext()).applyDefaultRequestOptions(fallback).load(R.drawable.ww).into(pictureImageView);
                break;
            case R.id.picture_button3:
                RequestOptions circleCrop = new RequestOptions().circleCrop();//切⚪
                Glide.with(getContext()).applyDefaultRequestOptions(circleCrop).load("http://qqpublic.qpic.cn/qq_public/0/0-2330923890-0837912F89A428FB25CCAB3808D4A1B0/0?fmt=jpg&size=80&h=506&w=900&ppv=1").into(pictureImageView);
                break;
            case R.id.picture_button4:
                RequestOptions placeholder = new RequestOptions().placeholder(R.drawable.ww);//加载中
                Glide.with(getContext()).applyDefaultRequestOptions(placeholder).load("https://i02piccdn.sogoucdn.com/2d52f09462ecb12a").into(pictureImageView);
                break;
            case R.id.picture_button5:
                RequestOptions error = new RequestOptions().error(R.drawable.ww);//加载中
                Glide.with(getContext()).applyDefaultRequestOptions(error).load("https://i04piccdn.sogoucdn.com/562959966d65eb5e").into(pictureImageView);
                break;
            case R.id.picture_button6:
                pictureImageView.setImageResource(R.drawable.ww);
                break;
        }
    }
}
